#coding=utf-8

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()

def update(t):
    plt.cla(); plt.title("t = %.1fs"%(t*0.1))
    plt.ylim(-2.5,2.5)
    # y = sin(x-t), x = [0, 30]
    # y = sin(x+t), x = [0, 30]
    x = np.arange(0,20,0.1)
    y1 = np.sin( x - 0.1*t )
    y2 = -np.sin( x + 0.1*t )
    y3 = np.sin( x + 0.1*t ) - np.sin( x - 0.1*t )
    plt.plot(x,y1, color='green' )
    #plt.plot(x,y2, color='blue' )
    #plt.plot(x,y3, linewidth=3, color='red')
    print("t = ", 0.1*t)
ani = animation.FuncAnimation(fig, update, range(30), interval=100)
plt.show()
#help(ani.save)
#ani.save('ani.gif', writer='ffmpeg', fps=80)